package com.hhit.bigscreenbackmanage.service.impl.pdf;

import com.hhit.bigscreenbackmanage.common.PageUtil;
import com.hhit.bigscreenbackmanage.dao.pdf.PdfMapper;
import com.hhit.bigscreenbackmanage.entity.pdf.PdfMlTree;
import com.hhit.bigscreenbackmanage.entity.pdf.Pdfml;
import com.hhit.bigscreenbackmanage.entity.pdf.Pdftz;
import com.hhit.bigscreenbackmanage.service.pdf.PdfService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Service
public class PdfServiceImpl implements PdfService {

    Logger logger = LoggerFactory.getLogger(PdfServiceImpl.class);

    @Autowired
    private PdfMapper pdfMapper;

    @Override
    public PageUtil<Pdftz> getPdftz(Map map) {
        PageUtil<Pdftz> page = new PageUtil<Pdftz>();
        List<Pdftz> userList =null;
        try {
            page.pageCount=Integer.parseInt(map.get("PAGESIZE").toString());
            page.init(pdfMapper.getCount(map),Integer.parseInt(map.get("PAGENO").toString()));//参数1：总行数，参数2：当前页
            map.put("rowNum",page.getRowNum());//当前页起始行号
            map.put("pageCount",Integer.parseInt(map.get("PAGESIZE").toString()));//每页行数
            userList = pdfMapper.getPdftz(map);
            page.setList(userList);
        } catch (Exception e) {
            logger.error("报错啦：" + e.getMessage());
        }
        return page;
    }

    @Override
    public List<PdfMlTree> getPdfml(Map map) {
        List<PdfMlTree> trees = new ArrayList<>();
        List<Pdfml> list = pdfMapper.getPdfml(map);
        // 循环赋值
        for (Pdfml pdfml : list) {
            PdfMlTree tree = new PdfMlTree();
            tree.setCode(pdfml.getMlbm());
            tree.setTitle(pdfml.getMlmc());
            tree.setLevel(pdfml.getCj());
            tree.setChecked(false);
            tree.setExpand(false);
            tree.setLoading(false);
            PdfMlTree[] child = new PdfMlTree[0];
            tree.setChildren(child);
            trees.add(tree);
        }
        return trees;
    }

    @Override
    public int addPdfml(Pdfml pdfml) {
        return pdfMapper.addPdfml(pdfml);
    }

    @Override
    public int addPdftz(Pdftz pdftz) {
        return pdfMapper.addPdftz(pdftz);
    }

    @Override
    public int findPdfml(Pdfml pdfml) {
        return pdfMapper.findPdfml(pdfml);
    }

    @Override
    public int findPdftz(Pdftz pdftz) {
        return pdfMapper.findPdftz(pdftz);
    }
}
